angular.module('proDetailsModule', []).controller('proDetailsCtr', ctrFn);

ctrFn.$inject = ['$scope', '$stateParams', '$filter','httpFactory','$location'];

function ctrFn($scope, $stateParams, $filter,httpFactory,$location) {
    $scope.goBack = function () {
        history.go(-1);
    };
    var proid = $stateParams.proid? $stateParams.proid:1;
    $scope.addShopCart = function () {
        var item = {id: proid, num: 1};
        var shopCart = LsyStorage.getItem('shopCart');
        shopCart = shopCart ? shopCart : [];
        var proItem = $filter('shopCartFilter')(shopCart, proid);
        if (!proItem) {
            shopCart.push(item);
        }
        LsyStorage.setItem('shopCart', shopCart);
    };
    httpFactory.getData('./src/datas/proData.json')
        .then(function (data) {
            var arr=[{id:proid}];
            $scope.newDatas=$filter('getShopCartFilter')(data,arr)[0];
        });
    /*立即购买*/
    $scope.buyNow=function(){
        var confirmOrderData=[];
        var obj={
            id:proid,
            num:1
        };
        confirmOrderData.push(obj);
        LsyStorage.setItem('confirmOrderDatas',confirmOrderData);
        $location.path('confirm_order');
    }
}

